<!DOCTYPE html>
<html>
  <!-- meta/link... -->
  



<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <!-- Global site tag (gtag.js) - Google Analytics -->


  <title>Mysql 进阶查询 (select 语句的高级用法) | 张不胖</title>

  <link rel="icon" type="image/x-icon, image/vnd.microsoft.icon" href="/favicon.ico">
  <link rel="stylesheet" href="https://at.alicdn.com/t/font_1911880_c1nvbyezg17.css">
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">

  
    <script>
        var themeModelId = '';
        if (themeModelId) {
            localStorage.setItem('modelId', themeModelId);
        }
    </script>
    
    <script src="https://cdn.jsdelivr.net/gh/yuang01/live2d-widget@latest/autoload.js"></script>
    <script>
        var live2dOpen = eval('true') || false;
        if (!live2dOpen) {
            localStorage.setItem('waifu-display', 1609323474481);
        }
    </script>
  
  
  
<link rel="stylesheet" href="/css/animate.min.css">

  
<link rel="stylesheet" href="/css/style.css">

  
  
    
<link rel="stylesheet" href="/js/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/js/shareJs/share.min.css">

  
  <style>
        @media (max-width: 992px) {
            #waifu {
                display: none;
            }
        }
    </style>
    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">

    

    <!-- import link -->
    
        
            
        
            
        
    
    <!-- import script -->
    
        
            <script src="/js/calendar.js"></script>
        
            <script src="/js/languages.js"></script>
        
            
        
            
        
    

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="张不胖" type="application/atom+xml">
</head>

  
  <!-- 依赖于jquery和vue -->
  <script src="/js/jquery3.5.1.js"></script>
  <script src="/js/vue2.6.11.js"></script>
  
  <body>
    <!-- 预加载动画 -->
    <!-- 页面预加载动画 -->

    
    <!-- 判断是否为暗黑风格 -->
    <!-- 判断是否为黑夜模式 -->
<script>
  let isDark = JSON.parse(localStorage.getItem('dark')) || JSON.parse('false');

  if (isDark) {
    $(document.body).addClass('darkModel');
  }
</script>

    <!-- 头部导航等 -->
    
<header class="header " id="navHeader"
  style="position: fixed;
  left: 0; top: 0; z-index: 10;width: 100%;"
>
  <div class="header-content">
    <div class="bars">
      <div id="appDrawer" class="sidebar-image">
  <div class="drawer-box-icon">
    <i class="fa fa-bars" aria-hidden="true" @click="showDialogDrawer"></i>
  </div>
  
  <transition name="fade">
    <div class="drawer-box_mask" v-cloak style="display: none;" v-show="visible" @click.self="cancelDialogDrawer">
    </div>
  </transition>
  <div class="drawer-box" :class="{'active': visible}">
    <div class="drawer-box-head bg-color">
      <img class="drawer-box-head_logo" src="/medias/logo.png" alt="logo">
      <h3 class="drawer-box-head_title">张不胖</h3>
      <h5 class="drawer-box-head_desc"></h5>
    </div>
    
    <div class="drawer-box-content">
      <ul class="drawer-box-content_menu">
        
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/" class="drawer-menu-item-link">
                  
                    <i class="fa fa-home" aria-hidden="true"></i>
                  
                  <span class="name">首页</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/musics" class="drawer-menu-item-link">
                  
                    <i class="fa fa-music" aria-hidden="true"></i>
                  
                  <span class="name">音乐</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/archives" class="drawer-menu-item-link">
                  
                    <i class="fa fa-archive" aria-hidden="true"></i>
                  
                  <span class="name">归档</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/tags" class="drawer-menu-item-link">
                  
                    <i class="fa fa-tags" aria-hidden="true"></i>
                  
                  <span class="name">标签</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/categories" class="drawer-menu-item-link">
                  
                    <i class="fa fa-bookmark" aria-hidden="true"></i>
                  
                  <span class="name">分类</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/about" class="drawer-menu-item-link">
                  
                    <i class="fa fa-user" aria-hidden="true"></i>
                  
                  <span class="name">关于</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/friends" class="drawer-menu-item-link">
                  
                  <span class="name">友情链接</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="javascript:;" class="drawer-menu-item-link has-children" @click="openOrCloseMenu(7)">
                  <span>
                    
                      <i class="fa fa-link"></i>
                    
                    <span class="name">更多</span>
                  </span>
                  <i class="fa fa-chevron-left arrow " :class="{'icon-rotate': isOpen(7)}" aria-hidden="true"></i>
                </a>
                <ul class="drawer-sub-menu" v-if="isOpen(7)">
                  
                  <li>
                    <a href="/gallery">
                      
                      <i class="fa fa-music" style="margin-top: -20px;"></i>
                      
                      <span>图库</span>
                    </a>
                  </li>
                  
                  <li>
                    <a target="_blank" rel="noopener" href="http://baidu.com">
                      
                      <i class="fa fa-film" style="margin-top: -20px;"></i>
                      
                      <span>百度</span>
                    </a>
                  </li>
                  
                </ul>
              
            </li>
          
        
        
          <li class="drawer-box-content_item">
            <a target="_blank" rel="noopener" href="https://github.com/zhangcun1113/hexo-theme-bamboo">
              <i class="fa fa-github" aria-hidden="true"></i>
              <span>Github</span>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</div>

<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appDrawer',
    data: {
      visible: false,
      top: 0,
      openArr: [],
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      isOpen(index) {
        if (this.openArr.includes(index)) {
          return true;
        } else {
          return false;
        }
      },
      openOrCloseMenu(curIndex) {
        const index = this.openArr.indexOf(curIndex);
        if (index !== -1) {
          this.openArr.splice(index, 1);
        } else {
          this.openArr.push(curIndex);
        }
      },
      showDialogDrawer() {
        this.visible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'width: 100%; height: 100%;overflow: hidden;';
      },
      cancelDialogDrawer() {
        this.visible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      }
    },
    created() {}
  })
</script>

    </div>
    <div class="blog-title" id="author-avatar">
      
        <div class="avatar">
          <img src="/medias/logo.png" alt="logo">
        </div>
      
      <a href="/" class="logo">张不胖</a>
    </div>
    <nav class="navbar">
      <ul class="menu">
        
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/" class="menu-item-link" title="首页">
                  
                    <i class="fa fa-home" aria-hidden="true"></i>
                  
                  <span class="name">首页</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/musics" class="menu-item-link" title="音乐">
                  
                    <i class="fa fa-music" aria-hidden="true"></i>
                  
                  <span class="name">音乐</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/archives" class="menu-item-link" title="归档">
                  
                    <i class="fa fa-archive" aria-hidden="true"></i>
                  
                  <span class="name">归档</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/tags" class="menu-item-link" title="标签">
                  
                    <i class="fa fa-tags" aria-hidden="true"></i>
                  
                  <span class="name">标签</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/categories" class="menu-item-link" title="分类">
                  
                    <i class="fa fa-bookmark" aria-hidden="true"></i>
                  
                  <span class="name">分类</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/about" class="menu-item-link" title="关于">
                  
                    <i class="fa fa-user" aria-hidden="true"></i>
                  
                  <span class="name">关于</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/friends" class="menu-item-link" title="友情链接">
                  
                  <span class="name">友情链接</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="javascript:;" class="menu-item-link" title="更多">
                  
                    <i class="fa fa-link"></i>
                  
                  <span class="name">更多</span>
                  <i class="fa fa-chevron-down arrow" aria-hidden="true"></i>
                </a>
                <ul class="sub-menu">
                  
                  <li>
                    <a href="/gallery">
                      
                      <i class="fa fa-music" style="margin-top: -20px;"></i>
                      
                      <span>图库</span>
                    </a>
                  </li>
                  
                  <li>
                    <a target="_blank" rel="noopener" href="http://baidu.com">
                      
                      <i class="fa fa-film" style="margin-top: -20px;"></i>
                      
                      <span>百度</span>
                    </a>
                  </li>
                  
                </ul>
              
            </li>
          
        
      </ul>
      
      
        <div id="appSearch">
  <div class="search"  @click="showDialog()"><i class="fa fa-search" aria-hidden="true"></i></div>
  <transition name="fade">
    <div class="message-box_wrapper" style="display: none;" v-cloak v-show="dialogVisible" @click.self="cancelDialogVisible()">
      <div class="message-box animated bounceInDown">
        <!-- <div class="close" style="overflow: hidden;">
          <i class="fa fa-close" aria-hidden="true" style="float:right;" @click.self="cancelDialogVisible()"></i>
        </div> -->
        <h2>
          <span>
            <i class="fa fa-search" aria-hidden="true"></i>
            <span class="title">本地搜索</span>
          </span>
          <i class="fa fa-close close" pointer style="float:right;" aria-hidden="true" @click.self="cancelDialogVisible()"></i>
        </h2>
        <form class="site-search-form">
          <input type="text"
            placeholder="请输入关键字"
            id="local-search-input" 
            @click="getSearchFile()"
            class="st-search-input"
            v-model="searchInput"
          />
        </form>
        <div class="result-wrapper">
          <div id="local-search-result" class="local-search-result-cls"></div>
        </div>
      </div>
    </div>
  </transition>
</div>
<script src="/js/local_search.js"></script>
<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appSearch',
    data: {
      dialogVisible: false,
      searchInput: '',
      top: 0,
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      showDialog() {
        this.dialogVisible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'overflow: hidden;';
      },
      getSearchFile() {
        if (!this.searchInput) {
          getSearchFile("/search.xml");
        }
      },
      cancelDialogVisible() {
        this.dialogVisible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      },
    },
    created() {}
  })
</script>
<!-- 解决刷新页面闪烁问题，可以在元素上添加display: none, 或者用vue.extend方法，详情：https://blog.csdn.net/qq_31393401/article/details/81017912 -->
<!-- 下面是搜索基本写法 -->
<!-- <script type="text/javascript" id="local.search.active">
  var inputArea = document.querySelector("#local-search-input");
  inputArea.onclick   = function(){ getSearchFile(); this.onclick = null }
  inputArea.onkeydown = function(){ if(event.keyCode == 13) return false }
</script> -->

      

    </nav>
  </div>
  
    <a target="_blank" rel="noopener" href="https://github.com/zhangcun1113/hexo-theme-bamboo" class="github-corner color-primary" aria-label="View source on GitHub"><svg width="60" height="60" viewBox="0 0 250 250" style="fill:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  
  
    <div id="he-plugin-simple"></div>
    <script>
      WIDGET = {
        CONFIG: {
          "modules": "012",
          "background": 5,
          "tmpColor": "4A4A4A",
          "tmpSize": 16,
          "cityColor": "4A4A4A",
          "citySize": 16,
          "aqiSize": 16,
          "weatherIconSize": 24,
          "alertIconSize": 18,
          "padding": "10px 10px 10px 10px",
          "shadow": "1",
          "language": "auto",
          "borderRadius": 5,
          "fixed": "false",
          "vertical": "middle",
          "horizontal": "center",
          "key": "2784dd3fcb1e4f0f9a9b579bf69641f2"
        }
      }
    </script>
    <script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script> 
    

    <!-- 当头部导航设置为背景透明的时候  -->
    
      <script src="/js/header/index.js" data-pjax></script>
    
</header>

    <!-- 需要在上面加载的js -->
    <script>
    function loadScript(src, cb) {
        setTimeout(function () {
            var HEAD = document.getElementsByTagName('head')[0] || document.documentElement;
            var script = document.createElement('script');
            script.setAttribute('type', 'text/javascript');
            if (cb) script.onload = cb;
            script.setAttribute('src', src);
            HEAD.appendChild(script);
        });
    }

    //https://github.com/filamentgroup/loadCSS
    var loadCSS = function (href, before, media, attributes) {
        var doc = window.document;
        var ss = doc.createElement("link");
        var ref;
        if (before) {
            ref = before;
        }
        else {
            var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes;
            ref = refs[refs.length - 1];
        }
        var sheets = doc.styleSheets;
        if (attributes) {
            for (var attributeName in attributes) {
                if (attributes.hasOwnProperty(attributeName)) {
                    ss.setAttribute(attributeName, attributes[attributeName]);
                }
            }
        }
        ss.rel = "stylesheet";
        ss.href = href;
        ss.media = "only x";
        function ready(cb) {
            if (doc.body) {
                return cb();
            }
            setTimeout(function () {
                ready(cb);
            });
        }
        ready(function () {
            ref.parentNode.insertBefore(ss, (before ? ref : ref.nextSibling));
        });
        var onloadcssdefined = function (cb) {
            var resolvedHref = ss.href;
            var i = sheets.length;
            while (i--) {
                if (sheets[i].href === resolvedHref) {
                    return cb();
                }
            }
            setTimeout(function () {
                onloadcssdefined(cb);
            });
        };
        function loadCB() {
            if (ss.addEventListener) {
                ss.removeEventListener("load", loadCB);
            }
            ss.media = media || "all";
        }
        if (ss.addEventListener) {
            ss.addEventListener("load", loadCB);
        }
        ss.onloadcssdefined = onloadcssdefined;
        onloadcssdefined(loadCB);
        return ss;
    };
    
</script>
 

<!-- 轮播图所需要的js -->
<script src="/js/swiper/swiper.min.js"></script>
<script src="/js/swiper/vue-awesome-swiper.js"></script>
<script src="/js/swiper/swiper.animate1.0.3.min.js"></script>


  <script src="/js/vue-typed-js/index.js"></script>


<!-- 首页的公告滚动插件的js需要重新加载 -->
<script src="/js/vue-seamless-scroll/index.js"></script>

<!-- 打字机效果js -->
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>


    <!-- 内容区域 -->
    <div id="safearea">
      <main class="main" id="pjax-container" style="margin-top: 0;">
        
 <!-- prismjs 代码高亮 -->
 
    
    <link href="/js/prism/prism-line-numbers.css" rel="stylesheet">
    
        <link href="/js/prism/prism.min.css" rel="stylesheet">
    

    <style>
        pre[class*="language-"] {
            overflow-y: hidden;
        }
        .line-numbers .line-numbers-rows {
            border: none;
        }
    </style>
  


<div class="bg-dark-floor" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -1;"></div>

<!-- 文章详情页顶部图片和标题 -->




<div class="post-detail-header lazyload" id="thumbnail_canvas" data-original="/medias/6.jpg" style="background-repeat: no-repeat; background-size: cover; 
  background-position: center center;position: relative;">
  <div class="post-detail-header-mask"></div>
  <canvas id="header_canvas"style="position:absolute;bottom:0;pointer-events:none;"></canvas>
  
  <div class="post-detail-header_info-box">
    <div class="title-box">
      <span class="title">
        Mysql 进阶查询 (select 语句的高级用法)
      </span>
    </div>
    
    
      
        <span class="post-detail-header_date">
          <i class="fa fa-calendar"></i> 发表于：2022-05-06 |
        </span>
      

      

      
        <div class="post-detail-header_wordcount">
          <span class="totalcount">
            <i class="fa fa-file-text-o"></i> 字数统计: 5.1k |
          </span>
  
          <span class="min2read">
            <i class="fa fa-clock-o"></i> 阅读时长: 23分钟 |
          </span>
  
          
            <span class="reading">
              <i class="fa fa-eye"></i> 阅读量：<span id="busuanzi_value_page_pv"></span>
            </span>
          
        </div>
      
    
  </div>
  
  
    <script src="/js/bubble/bubble.js"></script>
  
</div>



<div class="row justify-position">
  <div class="main-content">
    <article class="post post-detail">
      
      <div class="post-content">
        <pre><code>前言

在mysql 中，可以使用SELECT 语句来查询数据，查询数据是指从数据库中根据需求，使用不同的查询方式来获取不同的数据，是使用频率最高，最重要的操作。

今天给大家带来查询语句的高级语法

一、按关键字排序
1、使用order by语句来实现排序

2、排序可针对一个或多个字段

3、ASC：升序，默认排序方式

4、DESC：降序

5、order by的语法结构

select 字段1，字段2 from 表明 order by 字段1 desc|asc，字段2 desc|asc；

6、按单子段排序


按照成绩降序排序
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
| 20201003 | mazi     |      90 |
+----------+----------+---------+
mysql&gt; mysql&gt; select id,name,chengji from chengji where chengji&gt;50 ordhengji desc;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201003 | mazi     |      90 |
| 20201002 | zhangsan |      85 |
| 20201001 | lili     |      80 |
+----------+----------+---------+
3 rows in set (0.01 sec)

按照chengji升序排列  且&gt;50
mysql&gt; select id,name,chengji from chengji where chengji&gt;50 order by chengji asc;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
| 20201003 | mazi     |      90 |
+----------+----------+---------+
3 rows in set (0.00 sec)
　多字段排序　


主参考字段在前面，按照成绩降序，辅助参考字段写在后面，按照ID升序 先比较主参考字段，如果相同再按照辅助字段排序
mysql&gt; select id,name,chengji from chengji where chengji&gt;70 order by chengji desc,id asc;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201003 | mazi     |      90 |
| 20201002 | zhangsan |      85 |
| 20201004 | sisi     |      85 |
| 20201001 | lili     |      80 |
+----------+----------+---------+
4 rows in set (0.00 sec)　　
二、对结果进行分组　　
1、使用group by 语句来实现分组

2、通常结合聚合函数一起使用

3、可以按照一个或多个字段对结果进行分组

4、group by 的语法结构


按照成绩进行分组，并进行计数。统计成绩相同的那么数量
mysql&gt; select count(name),chengji from chengji where chengji&gt;79 group by chengji;
+-------------+---------+
| count(name) | chengji |
+-------------+---------+
|           1 |      80 |
|           2 |      85 |
|           1 |      90 |
+-------------+---------+
3 rows in set (0.00 sec)

按照上面的排序 在按照降序排列
mysql&gt; select count(name),chengji from chengji where chengji&gt;79 group by chengji desc;
+-------------+---------+
| count(name) | chengji |
+-------------+---------+
|           1 |      90 |
|           2 |      85 |
|           1 |      80 |
+-------------+---------+
3 rows in set (0.00 sec)　　
三、限制结果条目
1、只返回select查询结果的第一行或前几行

2、使用limit 语句限制条目

3、limit 语法结构

select 字段1，字段2 from 表名 limit [offset,] number;

offset: 位置偏移量，从0开始

number：返回记录行的最大数目


mysql&gt; select * from chengji;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
| 20201003 | mazi     |      90 |
| 20201004 | sisi     |      85 |
+----------+----------+---------+
4 rows in set (0.00 sec)
只显示前两行
mysql&gt; select id,name,chengji from chengji limit 2;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
+----------+----------+---------+
2 rows in set (0.00 sec)

mysql&gt; select * from chengji;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
| 20201003 | mazi     |      90 |
| 20201004 | sisi     |      85 |
+----------+----------+---------+
4 rows in set (0.00 sec)
限制显示结果，从第2行开始，显示两行
mysql&gt; select id,name,chengji from chengji limit 2,2;
+----------+------+---------+
| id       | name | chengji |
+----------+------+---------+
| 20201003 | mazi |      90 |
| 20201004 | sisi |      85 |
+----------+------+---------+
2 rows in set (0.00 sec)

显示前三行
mysql&gt; select id,name,chengji from chengji limit 3;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      80 |
| 20201002 | zhangsan |      85 |
| 20201003 | mazi     |      90 |
+----------+----------+---------+
3 rows in set (0.00 sec)　　
四、设置别名
1、使用as语句设置别名，关键字as可shenglue

2、设置别名时，保证不能从库中其他表或字段名称冲突

3、别名的语法结构

字段别名：

select 字段 from 表名 as 别名

设置字段的别名、
、mysql&gt; select count(*) as 总行数 from chengji;
+-----------+
| 总行数    |
+-----------+
|         4 |
+-----------+
1 row in set (0.00 sec)　　
 五、通配符
1、用于替换字符串中的部分字符

2、通常配合like一起使用，并协同where完成查询

3、常用的通配符

%：表示零个，一个或多个即任意字符

_: 表示单个字符


name字段中以z开头的任意记录
mysql&gt; select id,name from chengji where name like &#39;z%&#39;;
+----------+----------+
| id       | name     |
+----------+----------+
| 20201002 | zhangsan |
+----------+----------+
1 row in set (0.00 sec)

name字段中有‘mazi’，匹配最后的单个字符
mysql&gt; select id,name from chengji where name like &#39;maz_&#39;;
+----------+------+
| id       | name |
+----------+------+
| 20201003 | mazi |
+----------+------+
1 row in set (0.00 sec)

‘hang‘前面一个字符，后面任意多个字符
mysql&gt; select id,name from chengji where name like &#39;_hang%&#39;;
+----------+----------+
| id       | name     |
+----------+----------+
| 20201002 | zhangsan |
+----------+----------+
1 row in set (0.00 sec）　　
六、子查询
1、也称作为内查询或者嵌套查询

2、先于主查询被执行，其结果将作为外层主查询的条件

3、在增删改查中都可以使用子查询

4、支持多层嵌套

5、in 语句用来判断某个值是否在给定的结果集中


查看chengji表的ID是否有（20201001,20201002）
 
mysql&gt; select id,name from chengji where id in(20201001,20201002);
+----------+----------+
| id       | name     |
+----------+----------+
| 20201001 | lili     |
| 20201002 | zhangsan |
+----------+----------+
2 rows in set (0.00 sec)

先进行子查询 是否有chengji&gt;85  有则继续执行
mysql&gt; select id,name from chengji where id in(select id from chengji where chengji&gt;85);
+----------+------+
| id       | name |
+----------+------+
| 20201003 | mazi |
+----------+------+
1 row in set (0.00 sec)
没有则输出无
 
mysql&gt; select id,name from chengji where id in(select id from chengji where chengji&gt;100);
Empty set (0.01 sec)　　
多层嵌套

select、update、delete都支持多层嵌套


mysql&gt; select * from chengji where id in (select a.id from (select id from chengji where chengji=85) a);
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201002 | zhangsan |      85 |
| 20201004 | sisi     |      85 |
+----------+----------+---------+
2 rows in set (0.00 sec)
 
mysql&gt;

讲chengji表中chengji低于90的赋给临时表a，选择a表中的成绩字段的值进行修改，自身chengji减5
mysql&gt; update chengji set chengji=chengji-5 where id in (select a.id from (select id from chengji where chengji&lt;90) a);
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
 
mysql&gt; select * from chengji
    -&gt; ;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      75 |
| 20201002 | zhangsan |      80 |
| 20201003 | mazi     |      90 |
| 20201004 | sisi     |      80 |
+----------+----------+---------+
4 rows in set (0.00 sec)

mysql&gt; delete from chengji where id in(select a.id from (select id from chengji where chengji=90) a);
Query OK, 1 row affected (0.01 sec)
 
mysql&gt; select * from chengji;
+----------+----------+---------+
| id       | name     | chengji |
+----------+----------+---------+
| 20201001 | lili     |      75 |
| 20201002 | zhangsan |      80 |
| 20201004 | sisi     |      80 |
+----------+----------+---------+
3 rows in set (0.00 sec)　　
exit的用法

exists类似于if 后面执行成功前面的语句才会执行
mysql&gt; select name from chengji where exists (select id from chengji where name=&#39;lili&#39;);
+----------+
| name     |
+----------+
| lili     |
| zhangsan |
| sisi     |
+----------+
3 rows in set (0.00 sec)
exists后面只能加select语句，执行成功前面的才执行，不成功前面不执行。

七、null值　　
null：真空（什么都没有）

&#39;&#39;:还有空气

表示缺失的值

与数字0或空白（spaces）不同

使用is null 或者is not null 进行判断

null值和真空（&#39;&#39;）的区别

空值长度为零，不占空间，null值得长度为null，占用空间

is null无法判断空值

空值使用‘=’或者‘&lt;&gt;’　来处理

count（）计算是，null会忽略，空值会加入计算

count（）计算时，null会被忽略
mysql&gt; select * from aa;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
+------+------+--------+
4 rows in set (0.00 sec)
 
mysql&gt; select count(fenshu) from aa;
+---------------+
| count(fenshu) |
+---------------+
|             3 |
+---------------+
1 row in set (0.00 sec)

查询fenshu字段为null的记录
mysql&gt; select * from aa;                                              
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    5 | titi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    4 | didi |   NULL |
+------+------+--------+
29 rows in set (0.00 sec)
 
mysql&gt; select * from aa where fenshu is null;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    4 | didi |   NULL |
|    5 | titi |   NULL |
|    4 | didi |   NULL |
|    4 | didi |   NULL |
|    4 | didi |   NULL |
|    4 | didi |   NULL |
|    4 | didi |   NULL |
|    4 | didi |   NULL |
+------+------+--------+
8 rows in set (0.00 sec)

查询fenshu字段不为null的记录
mysql&gt; select * from aa where fenshu is not null;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
|    1 | qiqi |     80 |
|    2 | sisi |     85 |
|    3 | lili |     85 |
+------+------+--------+
21 rows in set (0.00 sec)　　

count计数时 空值也会加入计数
mysql&gt; select * from cc;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi | 80     |
|    2 | sisi | 85     |
|    3 | lili | 85     |
|    4 | didi | NULL   |
|    5 | didi |        |
+------+------+--------+
5 rows in set (0.00 sec)
 
mysql&gt; select count(fenshu) from cc;
+---------------+
| count(fenshu) |
+---------------+
|             4 |
+---------------+
1 row in set (0.00 sec)
　　

八、正则表达式
1、根据指定的匹配模式匹配记录中符合要求的特殊字符

2、使用regexp关键字指定匹配模式

3、常用匹配模式
</code></pre>
<p>   <img "" class="lazyload placeholder" data-original="/images/pasted-65.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> ①：以特定字符串开头的记录

mysql&gt; select id,name,fenshu from cc where name regexp ‘^z’;

②：以特定字符串结尾的记录

mysql&gt; select id,name,fenshu from cc where name regexp ‘u$’;

③：包含指定字符串的记录

mysql&gt; select id,name,fenshu from cc where name regexp &#39;lili&#39;;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    3 | lili | 85     |
+------+------+--------+
1 row in set (0.00 sec)
 
mysql&gt; 　　
④、


mysql&gt; select id,name,fenshu from cc where name regexp &#39;l..i&#39;;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    3 | lili | 85     |
+------+------+--------+
1 row in set (0.00 sec)　　
 ⑤、匹配包含或者关系的记录

mysql&gt; select id,name,fenshu from cc where name regexp &#39;li|qi&#39;;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi | 80     |
|    3 | lili | 85     |
+------+------+--------+
2 rows in set (0.00 sec)　　
⑥、“*”匹配前面字符的任意多次


正表达式中*代表匹配前面字符任意多次，只写一个*没意义
name字段中匹配l任意多次，则匹配所有
mysql&gt; select * from cc where name regexp &#39;*&#39;;
ERROR 1139 (42000): Got error &#39;repetition-operator operand invalid&#39; from regexp
mysql&gt; select * from cc where name regexp &#39;l*&#39;;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    1 | qiqi | 80     |
|    2 | sisi | 85     |
|    3 | lili | 85     |
|    4 | didi | NULL   |
|    5 | didi |        |
+------+------+--------+
5 rows in set (0.00 sec)　　
⑦、“+”匹配前面字符至少一次
mysql&gt; select * from cc where name regexp ‘z+’;

⑧、匹配指定字符集中的任意一个


mysql&gt; select * from cc where name regexp &#39;^[d-l]&#39;;
+------+------+--------+
| id   | name | fenshu |
+------+------+--------+
|    3 | lili | 85     |
|    4 | didi | NULL   |
|    5 | didi |        |
+------+------+--------+
3 rows in set (0.00 sec)
方括号“[]”指定了一个字符集合，只匹配其中的一个字符。“”不仅可以放到左侧，也可以放到方括号内，放到左侧表示以这些字符集内的字符开头，而放到方括号内则表示不在指定的字符集合内的字符。例如“[d-f]”表示除 d、e、f 以外的任何字符。

九、运算符
用于对记录中的字段值进行运算

Mysql 的运算符共有四种，分别是：算术运算符、比较运算符、逻辑运算符和位运算符

1、算术运算符
</code></pre>
<p>   <img "" class="lazyload placeholder" data-original="/images/pasted-66.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code>以select命令来实现最基础的加减乘除运算，具体操作如下

mysql&gt; select 1+2,1-2,1*2,10/2,10%3;
+-----+-----+-----+--------+------+
| 1+2 | 1-2 | 1*2 | 10/2   | 10%3 |
+-----+-----+-----+--------+------+
|   3 |  -1 |   2 | 5.0000 |    1 |
+-----+-----+-----+--------+------+
1 row in set (0.00 sec)
整数相除，出来的结果是浮点型的。
在除法运算和求余数运算中，除数不能为 0，若除数是 0，返回的结果则为 NULL。
需要注意的是，如果有多个运算符，按照先乘除后加减的优先级进行运算。　　
   
mysql&gt; select 10/0,10%0;
+------+------+
| 10/0 | 10%0 |
+------+------+
| NULL | NULL |
+------+------+
1 row in set (0.00 sec)

mysql&gt; select 1+2*3;
+-------+
| 1+2*3 |
+-------+
|     7 |
+-------+
1 row in set (0.00 sec)

mysql&gt; select (1+2)*3;
+---------+
| (1+2)*3 |
+---------+
|       9 |
+---------+
1 row in set (0.00 sec)
　　注意：某些字符串类型的字段存储的数字型字符串，这些字段在进行算术运算时将会被自动转换为数字的值。如果字符串的开始部分是数字，在转换时将被转换为这个数字。如果是既包含字符又包含数字得的混合字符串，无法转换为数字时，将被转换为 0。


mysql&gt; select 3*&#39;3i&#39;
    -&gt; ;
+--------+
| 3*&#39;3i&#39; |
+--------+
|      9 |
+--------+
1 row in set, 1 warning (0.00 sec)
 
mysql&gt; select 3*&#39;i3i&#39;;
+---------+
| 3*&#39;i3i&#39; |
+---------+
|       0 |
+---------+
1 row in set, 1 warning (0.00 sec)
2、比较运算符
</code></pre>
<p>   <img "" class="lazyload placeholder" data-original="/images/pasted-67.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" ">
    　</p>
<pre><code> （1） 等于运算符
用来判断数字、字符串和表达式是否相等的，如果相等则返回 1，如果不相等则返回 0。其中字符的比较是根据 ASCII 码来判断的。
ASCII码表转换：
0-48，1-49，…9-57
A-65，B-66
a-97，b-98


mysql&gt; select 1=3,2=&#39;2&#39;,&#39;e&#39;=&#39;e&#39;,&#39;r&#39;=null;
+-----+-------+---------+----------+
| 1=3 | 2=&#39;2&#39; | &#39;e&#39;=&#39;e&#39; | &#39;r&#39;=null |
+-----+-------+---------+----------+
|   0 |     1 |       1 |     NULL |
+-----+-------+---------+----------+
1 row in set (0.00 sec)
比较规则：
如果两者都是整数，则按照整数值进行比较。
如果一个整数一个字符串，则会自动将字符串转换为数字，再进行比较。
如果两者都是字符串，则按照字符串进行比较。
如果两者中至少有一个值是 NULL，则比较的结果是 NULL。
（2） 不等于运算符
不等于号有两种写法，分别是&lt;&gt;或者!=，用于针对数字、字符串和表达式不相等的比较。如果不相等则返回 1，如果相等则返回 0。
需要注意的是不等于运算符不能用于判断 NULL。


mysql&gt; select &#39;ta&#39;!=&#39;tat&#39;,1&lt;&gt;2,2.4&lt;&gt;2,&#39;r&#39;&lt;&gt;null;
+-------------+------+--------+-----------+
| &#39;ta&#39;!=&#39;tat&#39; | 1&lt;&gt;2 | 2.4&lt;&gt;2 | &#39;r&#39;&lt;&gt;null |
+-------------+------+--------+-----------+
|           1 |    1 |      1 |      NULL |
+-------------+------+--------+-----------+
1 row in set (0.00 sec
（3） 大于、大于等于、小于、小于等于运算符
注意：都不能用于判断NULL。


mysql&gt; select &#39;a&#39;&lt;&#39;b&#39;,(2+3)&gt;=(4+1),4&gt;4,&#39;p&#39;&gt;null;
+---------+--------------+-----+----------+
| &#39;a&#39;&lt;&#39;b&#39; | (2+3)&gt;=(4+1) | 4&gt;4 | &#39;p&#39;&gt;null |
+---------+--------------+-----+----------+
|       1 |            1 |   0 |     NULL |
+---------+--------------+-----+----------+
1 row in set (0.00 sec)
（4） IS NULL、IS NOT NULL
IS NULL 判断一个值是否为 NULL，如果为 NULL 返回 1，否则返回 0。
IS NOT NULL 判断一个值是否不为 NULL，如果不为 NULL 返回 1，否则返回 0。


mysql&gt; select &#39;p&#39; is null,null is null,&#39;null&#39; is not null;
+-------------+--------------+--------------------+
| &#39;p&#39; is null | null is null | &#39;null&#39; is not null |
+-------------+--------------+--------------------+
|           0 |            1 |                  1 |
+-------------+--------------+--------------------+
1 row in set (0.00 sec)
&#39;null&#39;是字符串，不是null
（5） between and
用于判断一个值是否落在某两个值之间
例如，判断某数字是否在另外两个数字之间，也可以判断某英文字母是否在另外两个字母之间


mysql&gt; select 15 between 8 and 20,&#39;c&#39; between &#39;d&#39; and &#39;z&#39;;
+---------------------+-------------------------+
| 15 between 8 and 20 | &#39;c&#39; between &#39;d&#39; and &#39;z&#39; |
+---------------------+-------------------------+
|                   1 |                       0 |
+---------------------+-------------------------+
1 row in set (0.00 sec)
（6） least、greatest
LEAST：当有两个或者多个参数时，返回其中的最小值。如果其中一个值为 NULL，则返回结果就为 NULL。
GREATEST：当有两个或者多个参数时，返回其中的最大值。如果其中一个值为 NULL， 则返回结果就为 NULL。


mysql&gt; select least(1,2,3) as zishu,greatest(&#39;j&#39;,&#39;d&#39;,&#39;z&#39;) as max;
+-------+-----+
| zishu | max |
+-------+-----+
|     1 | z   |
+-------+-----+
1 row in set (0.00 sec)
 
mysql&gt; select least(1,2,3,null) as zishu,greatest(&#39;j&#39;,&#39;d&#39;,&#39;z&#39;) as max;
+-------+-----+
| zishu | max |
+-------+-----+
|  NULL | z   |
+-------+-----+
1 row in set (0.00 sec)
（7） in、not in
IN 判断一个值是否在对应的列表中，如果是返回 1，否则返回 0。
NOT IN 判断一个值是否不在对应的列表中，如果不是返回 1，否则返回 0。


mysql&gt; select 3 in (1,3,4),&#39;c&#39; not in (&#39;c&#39;,&#39;d&#39;,&#39;b&#39;);
+--------------+--------------------------+
| 3 in (1,3,4) | &#39;c&#39; not in (&#39;c&#39;,&#39;d&#39;,&#39;b&#39;) |
+--------------+--------------------------+
|            1 |                        0 |
+--------------+--------------------------+
1 row in set (0.00 sec)
（8） like、not like
LIKE 用来匹配字符串，如果匹配成功则返回 1，反之返回 0；NOT LIKE 正好跟 LIKE 相反。
LIKE 支持两种通配符：’%’ 用于匹配任意数目的字符，而’_’只能匹配一个字符。　　


mysql&gt; select &#39;zhangsan&#39; like &#39;zh%&#39;,&#39;lisi&#39; like &#39;lis_&#39;,&#39;asc&#39; not like &#39;_sc&#39;;
+-----------------------+--------------------+----------------------+
| &#39;zhangsan&#39; like &#39;zh%&#39; | &#39;lisi&#39; like &#39;lis_&#39; | &#39;asc&#39; not like &#39;_sc&#39; |
+-----------------------+--------------------+----------------------+
|                     1 |                  1 |                    0 |
+-----------------------+--------------------+----------------------+
1 row in set (0.00 sec)
3.逻辑运算符
又被称为布尔运算符
用来判断表达式的真假
</code></pre>
<p>  <img "" class="lazyload placeholder" data-original="/images/pasted-68.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> （1）逻辑非
逻辑非将跟在它后面的逻辑测试取反，把真变为假，把假变为真。
如果 NOT 后面的操作数为 0 时，所得值为 1；如果操作数为非 0 时，所得值为 0；如果操作数为 NULL 时，所得值为 NULL。
注意：非0值都是1


mysql&gt; select not 2,! 0,not (5-5),! null;
+-------+-----+-----------+--------+
| not 2 | ! 0 | not (5-5) | ! null |
+-------+-----+-----------+--------+
|     0 |   1 |         1 |   NULL |
+-------+-----+-----------+--------+
1 row in set (0.00 sec)
（2）逻辑与
如果所有值都是真返回 1，否则返回 0。

逻辑与运算只要遇到0就是0
mysql&gt; select 3 and 4,5 &amp;&amp; 0,0 &amp;&amp; null,2 and null;
+---------+--------+-----------+------------+
| 3 and 4 | 5 &amp;&amp; 0 | 0 &amp;&amp; null | 2 and null |
+---------+--------+-----------+------------+
|       1 |      0 |         0 |       NULL |
+---------+--------+-----------+------------+
1 row in set (0.00 sec)
（3）逻辑或（最好用or）
逻辑或表示包含的操作数，任意一个为非零值并且不是 NULL 值时，返回 1，否则返回0


mysql&gt; select 2 or 0,3 or 5,0 or 0,0 or null,2 or null;
+--------+--------+--------+-----------+-----------+
| 2 or 0 | 3 or 5 | 0 or 0 | 0 or null | 2 or null |
+--------+--------+--------+-----------+-----------+
|      1 |      1 |      0 |      NULL |         1 |
+--------+--------+--------+-----------+-----------+
1 row in set (0.00 sec)
（4）逻辑异或
两个非 NULL 值的操作数，如果两者都是 0 或者都是非 0，则返回 0；如果一个为 0， 另一个为非 0，则返回结果为 1；
当任意一个值为 NULL 时，返回值为 NULL。


mysql&gt; select 0 xor 0,0 xor 1,2 xor 3,3 xor null;
+---------+---------+---------+------------+
| 0 xor 0 | 0 xor 1 | 2 xor 3 | 3 xor null |
+---------+---------+---------+------------+
|       0 |       1 |       0 |       NULL |
+---------+---------+---------+------------+
1 row in set (0.00 sec)
运算总结：
and运算，只要碰到0就是0，（非0和null是null）
or运算，只要碰到非0值就是1，（0和null是null）
异或运算，只要碰到null都是null
</code></pre>
<p>  <img "" class="lazyload placeholder" data-original="/images/pasted-69.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> 4.位运算符
位运算符实际上是对二进制数进行计算的运算符
    

mysql&gt; select 12&amp;13,11|12,10^15,3&amp;~1;
+-------+-------+-------+------+
| 12&amp;13 | 11|12 | 10^15 | 3&amp;~1 |
+-------+-------+-------+------+
|    12 |    15 |     5 |    2 |
+-------+-------+-------+------+
1 row in set (0.00 sec)
位运算方法：
按位与运算
10–》1010
15–》1111
1010 --》10
按位与运算（&amp;），是对应的二进制位都是 1 的，它们的运算结果为 1，否则为 0

按位或运算
10–》1010
15–》1111
1111–》15
按位或运算（|），是对应的二进制位只要是 1 的，它们的运算结果就为 1，否则为 0

按位异或运算
10–》1010
15–》1111
0101–》5
按位异或运算（^），是对应的二进制位不相同时，运算结果 1，否则为 0

按位取反运算
1–》0001
~1–》1110
5–》0101
0100–》4
按位取反（~），是对应的二进制数逐位反转，即 1 取反后变为 0, 0 取反后变为 1


mysql&gt; select 1&lt;&lt;2,10&gt;&gt;2;
+------+-------+
| 1&lt;&lt;2 | 10&gt;&gt;2 |
+------+-------+
|    4 |     2 |
+------+-------+
1 row in set (0.00 sec)
按位左移运算
1&lt;&lt;2
1–》0001
按位左移2位，空缺处补0
0100–》4

10&lt;&lt;3
10–》1010
按位左移3位，空缺处补0
1010000–》80
按位右移运算
10&gt;&gt;2
10–》1010
按位右移2位，多余的位数直接删除
0010–》2

15&gt;&gt;2
15–》1111
按位右移2位，多余的位数直接删除
0011–》3
常用的运算符优先级
</code></pre>
<p>  <img "" class="lazyload placeholder" data-original="/images/pasted-71.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> 十、连接查询
通常都是将来自两个或多个表的行结合起来，基于这些表之间的共同字段，进行数据的拼接。
要先确定一个主表作为结果集，然后将其他表的行有选择性的连接到选定的主表结果集上。

使用较多的连接查询包括：内连接、左连接和右连接
1.内连接
在from子句中使用关键字 inner join 来连接多张表，并使用 on子句设置连接条件。
mysql&gt; select info.name,hob.hobbyname from info inner join hob on info.hobby=hob.id;
±---------±-------------+
| name | hobbyname |
±---------±-------------+
| zhangsan | 人工智能 |
| zhaosi | 人工智能 |
| wangwu | 云计算 |
| zhaoliu | 人工智能 |
| heiqi | 云计算 |
±---------±-------------+
内连接是系统默认的表连接，所以在 FROM 子句后可以省略 INNER 关键字，只使用关键字 JOIN。同时有多个表时，也可以连续使用 INNER JOIN 来实现多表的内连接，不过为了更好的性能，建议最好不要超过三个表。
2.外连接
左连接，主表在左边，主表内容会全部显示出来，在从表中没匹配到的以NULL显示出来
</code></pre>
<p> <img "" class="lazyload placeholder" data-original="/images/pasted-72.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> 右连接，主表在右边，主表内容会全部显示出来，在从表中没匹配到的以NULL显示出来
</code></pre>
<p> <img "" class="lazyload placeholder" data-original="/images/pasted-73.png" src="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt=" "></p>
<pre><code> 修改表的结构

alter table old_name rename new_name; --修改表名
 
alter table test add  column add_name varchar(10); --添加表列
 
alter table test drop  column del_name; --删除表列
 
alter table test modify address char(10) --修改表列类型
# alter table test change address address  char(40)
 
 
alter table test change  column address address1 varchar(30)--修改表列名
</code></pre>

      </div>
      <div class="post-tags-categories">
        
      </div>
      
        <div class="copyright">
  <ul class="post-copyright">
    <li class="post-copyright-author">
    <strong>作者:  </strong>张存</a>
    </li>
    <li class="post-copyright-link">
    <strong>文章链接:  </strong>
    <a href="/2022/05/06/mysql-jin-jie-cha-xun-select-yu-ju-de-gao-ji-yong-fa/" target="_blank" title="Mysql 进阶查询 (select 语句的高级用法)">https://blog.zhangcun.store/2022/05/06/mysql-jin-jie-cha-xun-select-yu-ju-de-gao-ji-yong-fa/</a>
    </li>
    <li class="post-copyright-license">
      <strong>版权声明:   </strong>
      本网站所有文章除特别声明外,均采用 <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
      许可协议。转载请注明出处!
    </li>
  </ul>
<div>
      
    </article>
    <!-- 上一篇文章和下一篇文章 -->
    
      <!-- 文章详情页的上一页和下一页 -->
<div class="post-nav">



  
  <div class="post-nav-prev post-nav-item">
    <div class="post-nav-img lazyload" data-original="/medias/15.jpg" style="background-size: cover; 
      background-position: center center;">
    </div>
    <a href="/2022/05/06/docker-mysql-ke-hu-duan-ssl-connection-error-error-1425f102-ssl-routines-unsupported-protocol/" class="post-nav-link">
      <div class="title">
        <i class="fa fa-angle-left"></i> 上一篇:
        <div class="title-text">docker mysql客户端：SSL connection error: error:1425F102:SSL routines: unsupported protocol</div>
      </div>
      
      <!-- <div class="content">
        docker mysql 客户端报错
[root@1317c0f71d3d /]# mysql -h192.168.10
      </div> -->
    </a>
  </div>



  
  <div class="post-nav-next post-nav-item">
    <div class="post-nav-img lazyload" data-original="/medias/1.jpg" style="background-size: cover; 
      background-position: center center;">
    </div>
    <a href="/2022/05/06/elasticsearch-ji-qun-zhuang-tai-cha-xun/" class="post-nav-link">
      <div class="title">
        下一篇: <i class="fa fa-angle-right"></i>
        <div class="title-text">Elasticsearch- 集群状态查询</div>
      </div>
      <!-- <div class="content">
        1. 查看ES集群健康状态

curl -XGET &#39;http://localhost:8200/_cluste
      </div> -->
    </a>
  </div>

</div>

    
    

    <!-- 打赏 -->
    
      <div id="appDonate" class="post-donate">
  <div id="donate_board" class="donate_bar center" ref="donate">
    <a id="btn_donate" class="btn_donate" href="javascript:;" title="打赏" @click="showDialogDrawer()"></a>
  </div>
  <transition name="fade">
    <div 
      class="donate-box-mask"
      v-cloak 
      v-if="visible"
      @click="cancelDialogDrawer()"
    >
    </div>
  </transition>
  <transition name="bounce">
    <div class="donate-box" v-cloak v-if="visible">
      <div class="donate-box_close">
        <i class="fa fa-times" aria-hidden="true" @click="cancelDialogDrawer" pointer></i>
      </div>
      <div class="donate-box_title">
        <h4>
          你的赏识是我前进的动力
        </h4>
      </div>
      <div class="donate-box_tab">
        <div class="Alipay" pointer :class="{'active': tabActive === 'Alipay'}" @click="changeTabActive('Alipay')">
          支付宝
        </div>
        <div class="WeChatpay" pointer :class="{'active': tabActive === 'WeChatpay'}" @click="changeTabActive('WeChatpay')">
          微信
        </div>
      </div>
      <div class="donate-box_img">
        <div class="AlipayImg" v-if="tabActive === 'Alipay'">
          <img src="/medias/zfb.jpg" alt="支付宝打赏" />
        </div> 
        <div class="WeChatpayImg" v-if="tabActive === 'WeChatpay'">
          <img src="/medias/wx.jpg" alt="微信打赏" />
        </div>
      </div>
    </div>
  </transition>
</div>

<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appDonate',
    data: {
      visible: false,
      tabActive: 'Alipay',
      top: 0,
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      showDialogDrawer() {
        this.visible = true;
        // 防止页面滚动，只能让弹框滚动
        // function getScroll() {
        //   return {
        //     left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
        //     top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
        //   };
        // }
        this.top = $(document).scrollTop() // or getScroll().top
        // console.log('aa', $('.main-content'));
        body.style.cssText = 'overflow: hidden;';
      },
      cancelDialogDrawer() {
        this.visible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      },
      changeTabActive(name) {
        this.tabActive = name;
      }
    },
    created() {}
  })
</script>
    

    <!-- 分享 -->
    
      <!-- https://github.com/overtrue/share.js -->
<!-- 文章详情页的分享 -->
<div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>

<script src="/js/shareJs/social-share.min.js"></script>
</script>

<style>
  .social-share {
    margin: 20px 0;
  }
</style>


    
    
    <!-- 评论 -->
    <!-- 评论 -->

  <div id="myComment">
    
      <div id="gitment-container"></div>

    
  </div>

<!-- comment script in themes\hexo-theme-bamboo\layout\_partial\scripts\index.ejs -->


  </div>

  <!-- 目录 -->
  <!-- 文章详情页右侧目录 -->

  <div class="toc-aside">
    <div class="toc-main">
      <div class="toc-aside-title">
        <i class="fa fa-list-ul" aria-hidden="true"></i><span>本文目录</span>
        
          <div class="toc-open-close">本文目录</div>
        
      </div>
      <div class="toc-content">
        <div class="toc"></div>
      </div>
    </div>
  </div>
  <!-- js在scripts目录下的的toc.ejs里面 -->
  

  <script>
    function openBtnClickFn () {
      let openOrCloseBtn = $('.toc-aside .toc-aside-title .toc-open-close');
      let open = eval('' || 'true');
      openOrCloseBtn.click(function() {
        if (open === true) {
          $(".toc-aside").css({'width': 0, 'padding': 0});
          $(".toc-content").css({'width': 0});
          $(".toc-aside-title span, .toc-aside-title i").css({'display': 'none'});
          $(".main-content").css({'width': '75%', 'margin': '10px auto'});
          open = false;
        } else {
          $(".toc-aside").css({'width': '300px', 'padding': '0 10px'});
          $(".toc-content").css({'width': '300px'});
          $(".toc-aside-title span, .toc-aside-title i").css({'display': 'inline-block'});
          $(".main-content").css({'width': '65%', 'margin-right': '10px', 'margin-left': 'calc(35% - 350px)'});
          open = true;
        }
      });
    };
    openBtnClickFn();
    document.addEventListener('pjax:complete', function () {
      openBtnClickFn();
    })
  </script>


  

  <!-- 图片放大 Wrap images with fancybox support -->
  <script src="/js/wrapImage.js"></script>
</div>

<!-- 文章详情页背景图 -->
<div id="appBgSwiper" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -2;" :style="{'background-color': bgColor ? bgColor : 'transparent'}">
    <transition-group tag="ul" :name="names">
        <li v-for='(image,index) in img' :key='index' v-show="index === mark" class="bg-swiper-box">
            <img :src="image" class="bg-swiper-img">
        </li>
    </transition-group>
</div>
<script>
    var vm = new Vue({
        el: '#appBgSwiper',
        data: {
            names: '' || 'fade' || 'fade', // translate-fade fade
            mark: 0,
            img: [],
            bgColor: '',
            time: null
        },
        methods: {   //添加方法
            change(i, m) {
                if (i > m) {
                    // this.names = 'fade';
                } else if (i < m) {
                    // this.names = 'fade';
                } else {
                    return;
                }
                this.mark = i;
            },
            prev() {
                // this.names = 'fade';
                this.mark--;
                if (this.mark === -1) {
                    this.mark = 3;
                    return
                }
            },
            next() {
                // this.names = 'fade';
                this.mark++;
                if (this.mark === this.img.length) {
                    this.mark = 0;
                    return
                }
            },
            autoPlay() {
                // this.names = 'fade';
                this.mark++;
                if (this.mark === this.img.length) {
                    this.mark = 0;
                    return
                }
            },
            play() {
                let bgImgDelay = '' || '180000'
                let delay = parseInt(bgImgDelay) || 180000;
                this.time = setInterval(this.autoPlay, delay);
            },
            enter() {
                clearInterval(this.time);
            },
            leave() {
                this.play();
            }
        },
        created() {
            this.play()
        },
        beforeDestroy() {
            clearInterval(this.time);
        },
        mounted() {
            let prop = ''|| '';
            let isImg = prop.includes('.bmp') || prop.includes('.jpg') || prop.includes('.png') || prop.includes('.tif') || prop.includes('.gif') || prop.includes('.pcx') || prop.includes('.tga') || prop.includes('.exif') || prop.includes('.fpx') || prop.includes('.psd') || prop.includes('.cdr') || prop.includes('.pcd') || prop.includes('.dxf') || prop.includes('.ufo') || prop.includes('.eps') || prop.includes('.ai') || prop.includes('.raw') || prop.includes('.WMF') || prop.includes('.webp') || prop.includes('.jpeg') || prop.includes('http://') || prop.includes('https://') 
            if (isImg) {
                let img = prop.split(',');
                let configRoot = '/'
                let arrImg = [];
                img.forEach(el => {
                    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
			        var objExp = new RegExp(Expression);

                    if(objExp.test(el)) {
                        // http or https
                        arrImg.push(el);
                    } else {
                        // 非http or https开头
                        // 本地文件
                        let firstStr = el.charAt(0);
                        if (firstStr == '/') {
                            el = el.substr(1); // 删除第一个字符 '/',因为 configRoot最后一个字符为 /
                        }
                        el = configRoot + el;
                        arrImg.push(el);
                    }
                })
                this.img = arrImg;
            } else {
                this.bgColor = prop;
            }
        }
    })
</script>

<style>
    .bg-swiper-box {
        position: absolute;
        display: block;
        width: 100%;
        height: 100%;
    }
    .bg-swiper-img {
        object-fit: cover;
        width: 100%;
        height: 100%;
    }
</style>

      </main>
    </div>

    <!-- 页脚 -->
    
  
  <div class="footer bg-color">
    <div class="footer-main">
      
        
          <div class="link">
            
              
                <a href="/atom.xml" class="social">
                  
                    <i class="fa fa-rss" aria-hidden="true"></i>
                  
                </a>
              
            
              
                <a href="mailto:1776803208@qq.com" class="social">
                  
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                  
                </a>
              
            
              
                <a target="_blank" rel="noopener" href="https://github.com/zhangcun1113/hexo-theme-bamboo" class="social">
                  
                    <i class="fa fa-github" aria-hidden="true"></i>
                  
                </a>
              
            
              
                <a href="tencent://AddContact/?fromId=50&amp;fromSubId=1&amp;subcmd=all&amp;uin=1730241541" class="social">
                  
                    <i class="fa fa-qq" aria-hidden="true"></i>
                  
                </a>
              
            
          </div>
        
      
        
          <div class="footer-copyright">
            <p>Copyright © 2001 - 2023 <a href="https://blog.zhangcun.store">zhangcun</a> </p>

          </div>
        
      
        
          
            <!-- 不蒜子统计 -->
            <!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
      <i class="fa fa-eye" aria-hidden="true"></i>本站总访问量：<span id="busuanzi_value_site_pv"></span> 次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
      <i class="fa fa-users" aria-hidden="true"></i>本站访客数：<span id="busuanzi_value_site_uv"></span> 人
</span>

          
        
      
        
          <div class="footer-custom">
            
          </div>
        
      
    </div>
  </div>



    <!-- 渲染暗黑按钮 -->
    
      <div class="dark">
  <div class="dark-content">
    <i class="fa fa-moon-o" aria-hidden="true"></i>
    <!-- <span>关灯</span> -->
  </div>
  
</div>

<script>
  $(function() {
    let isDark = JSON.parse(localStorage.getItem('dark'))  || JSON.parse('false');
    if (isDark) {
      $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-lightbulb-o" aria-hidden="true"></i>
          </div>
          `
        );
    }
    $('.dark').click(function() {
      if ($(document.body).is('.darkModel')) {
        $(document.body).removeClass('darkModel');
        localStorage.setItem('dark', false);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-moon-o" aria-hidden="true"></i>
          </div>
          `
        );
      } else {
        $(document.body).addClass('darkModel');
        localStorage.setItem('dark', true);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-lightbulb-o" aria-hidden="true"></i>
          </div>
          `
        );
      }
    })
  })
</script>
    
    <!-- 渲染回到顶部按钮 -->
    
      <div class="goTop top-btn-color" pointer>
  <i class="fa fa-arrow-up" aria-hidden="true"></i>
</div>
<script src="/js/goTop.js"></script>
    
    <!-- 渲染左下角音乐播放器 -->
    
      <link rel="stylesheet" href="/js/aplayer/APlayer@1.10.1.min.css">
<style>
.aplayer .aplayer-lrc p {
  
  font-size: 12px;
  font-weight: 700;
  line-height: 16px !important;
}

.aplayer .aplayer-lrc p.aplayer-lrc-current {
  
  font-size: 15px;
  color: #22b1eb;
}


.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
  left: -66px !important;
}

.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
  left: 0px !important;
}


</style>
<meting-js  
  class=""
  server="netease"
  type="playlist"
  id="8444991407"
  fixed='true'
  autoplay='true'
  theme='#22b1eb'
  loop='all'
  order='random'
  preload='auto'
  volume='0.7'
  list-folded='true'
>
</meting-js>

<!-- <style>
  #aplayer {
    position: fixed;
    left: 0;
    bottom: 300px;
  }
</style> -->
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>
    

    <!-- 图片放大 -->
    
      <script src="/js/fancybox/jquery.fancybox.min.js"></script>
    

    <!-- 百度解析 -->
    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <!-- 背景彩带 -->
    
    
    <script src="/js/app.js" data-pjax></script>
    
    <!-- 文章目录所需js -->
<link href="/js/tocbot/tocbot.css" rel="stylesheet">
<script src="/js/tocbot/tocbot.min.js"></script>

<script>
  var headerEl = 'h2, h3, h4',  //headers 
      content = '.post-detail',//文章容器
      idArr = {};  //标题数组以确定是否增加索引id
      //add #id
  var option = {
    // Where to render the table of contents.
    tocSelector: '.toc',
    // Where to grab the headings to build the table of contents.
    contentSelector: content,
    // Which headings to grab inside of the contentSelector element.
    headingSelector: headerEl,
    scrollSmooth: true,
    scrollSmoothOffset: -80,
    headingsOffset: -($(window).height() * 0.4 - 45),
    positionFixedSelector: '.toc-main',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
  }
  if ($('.toc').length > 0) {

    $(content).children(headerEl).each(function () {
      //去除空格以及多余标点
      var headerId = $(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\：|\，|\。]/g, '');

      headerId = headerId.toLowerCase();
      if (idArr[headerId]) {
        //id已经存在
        $(this).attr('id', headerId + '-' + idArr[headerId]);
        idArr[headerId]++;
      }
      else {
        //id未存在
        idArr[headerId] = 1;
        $(this).attr('id', headerId);
      }
    });

    tocbot.init(option);
    
  }


  document.addEventListener('pjax:send', function () {
    if ($('.toc').length) {
      tocbot.destroy();
    }
  });

  document.addEventListener('pjax:complete', function () {
    if ($('.toc').length) {
      tocbot.init(option);
    }
  });

  
</script>

<style>
.is-position-fixed {
  position:sticky !important;
  top: 74px;
}
.toc-main ul {
  counter-reset: show-list;
}
.toc-main ul li::before {
  content: counter(item)".";
  display: block;
  position: absolute;
  left: 12px;
  top:0;
}
/* .toc > .toc-list {
  padding-left: 35px;
}
.toc>.toc-list li {
  list-style: decimal;
}
.toc-list {
  padding-left: 25px;
} */
</style> 

<!-- 渲染issues标签里的内容 -->
<script>
  function loadIssuesJS() {
    if ($(".post-detail").find(".issues-api").length == 0) {
      return;
    } 
    loadScript('/js/issues/index.js');
  };
  $(function () {
    loadIssuesJS();
  });
  document.addEventListener('pjax:complete', function () {
    if (typeof IssuesAPI == "undefined") {
      loadIssuesJS();
    }
  })
</script>

<!-- 输入框打字特效 -->
<!-- 输入框打字特效 -->

  <script src="/js/activate-power-mode.js"></script>
  <script>
    POWERMODE.colorful = true;  // 打开随机颜色特效
    POWERMODE.shake = false;    // 关闭输入框抖动
    document.body.addEventListener('input', POWERMODE);//监听打字事件
  </script>


<!-- markdown代码一键复制功能 -->

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/v-plugs-ayu/lib/ayu.css">
  <script src="https://cdn.jsdelivr.net/npm/v-plugs-ayu/lib/ayu.umd.min.js"></script>
  <script src="/js/clipboard/clipboard.min.js"></script>
  <div id="appCopy">
  </div>
  <script data-pjax>
    var vm = new Vue({
      el: '#appCopy',
      data: {
      },
      computed: {
      },
      mounted() {
        const that = this;
        var copy = '复制';
        /* code */
        var initCopyCode = function () {
          var copyHtml = '';
          copyHtml += '<button class="btn-copy" data-clipboard-snippet="" style="position:absolute;top:0;right:0;z-index:1;">';
          copyHtml += '<i class="fa fa-copy"></i><span>' + copy + '</span>';
          copyHtml += '</button>';
          $(".post-detail pre").not('.gutter pre').wrap("<div class='codeBox' style='position:relative;width:100%;'></div>")
          $(".post-detail pre").not('.gutter pre').before(copyHtml);
          new ClipboardJS('.btn-copy', {
            target: function (trigger) {
              return trigger.nextElementSibling;
            }
          });
        }
        initCopyCode();
        $('.btn-copy').unbind('click').bind('click', function () {
          doSomething();
        })
        $(document).unbind('keypress').bind('keypress', function (e) {
          if (e.ctrlKey && e.keyCode == 67) {
            doSomething();
            // 返回false, 防止重复触发copy事件  
            // return false;
          }
        })
        //  监听 ctrl + c事件  
        // $(document).unbind('keypress').bind('keypress', function (e) {
        //   if (e.ctrlKey && e.keyCode == 67) {
        //     doSomething();
        //     // 返回false, 防止重复触发copy事件  
        //     return false;
        //   }
        // })

        // // 鼠标右键的复制事件  
        // $(document).unbind('copy').bind('copy', function (e) {
        //   doSomething();
        // });

        function doSomething() {
          that.$notify({
            title: "成功",
            content: "代码已复制，请遵守相关授权协议。",
            type: 'success'
          })
        }
      },
      methods: {
      },
      created() { }
    })
  </script>


<!-- 图片懒加载 -->
<script src="/js/lazyload/lazyload@1.9.1.js"></script>
<script data-pjax>
  $(function () {
    $("div.lazyload, img.lazyload, a.lazyload").lazyload(
      {
        effect: "show",
        placeholder: "https://img10.360buyimg.com/ddimg/jfs/t1/159345/8/2271/222193/5ff7b36fEe49f5663/a95287c20385127f.gif"    //图片未加载出来时显示的占位图
      }
    );
  });
</script>

<!-- 卡片滚动动画 -->
   

<!-- 评论所需js -->

    
        <script type="text/javascript">
    var bamboo = {};
    bamboo.utterance = {};
    
    function check_utterance() {
        let isDark = JSON.parse(localStorage.getItem('dark'))  || JSON.parse('false');
        if (isDark) {
            bamboo.utterance.Theme = 'github-dark';
        } else {
            bamboo.utterance.Theme = 'github-light';
        }

        return document.getElementById("gitment-container");
    }
    comment_el = '#gitment-container';
    load_utterance = function () {
        if ($(comment_el).length) {
            // 匿名函数，防止污染全局变量
            const HEAD = check_utterance();
            
            var utterances = document.createElement('script');
            utterances.type = 'text/javascript';
            utterances.async = true;
            utterances.setAttribute('issue-term','pathname')
            utterances.setAttribute('theme', bamboo.utterance.Theme)
            utterances.setAttribute('repo','')
            utterances.crossorigin = 'anonymous';
            utterances.src = 'https://utteranc.es/client.js';
            // content 是要插入评论的地方
            document.getElementById('gitment-container').appendChild(utterances);
            
        }
    }

    function dark_utterance() {
        const HEAD = check_utterance();
        if (!HEAD) return;
        const message = {
            type: 'set-theme',
            theme: bamboo.utterance.Theme
        };
        const utteranceIframe = document.querySelector('iframe');
        utteranceIframe.contentWindow.postMessage(message, 'https://utteranc.es');
    }

    $(document).ready(load_utterance);
    document.addEventListener('pjax:complete', function () {
        load_utterance();
    });

    $('.dark').click(function() {
        setTimeout(() => {
            dark_utterance();
        });
    })
    
</script>

<style>
    .utterances {
        max-width: inherit!important;
    }
</style>
    


<!-- 鼠标点击特效 -->
<!-- 爱心点击 -->

	
		<canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 999; pointer-events: none;" ></canvas>
		<script src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>
		<script src="/js/cursor/explosion.min.js"></script>
	




    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" data-pjax></script>


    <!-- pjax -->
    

<!-- pjax -->


  <script src="/js/pjax@0.2.8/index.js"></script>
  
    <!-- 样式位于：source/css/_third-party/pjaxanimate.styl -->

<div class="pjax-animate">
  
    <div class="loading-circle"><div id="loader-circle"></div></div>
    <script>
      window.ShowLoading = function() {
        $(".loading-circle").css("display", "block");
      };
      window.HideLoading = function() {
        $(".loading-circle").css("display", "none");
      }
    </script>
  
	<script>
    document.addEventListener('pjax:complete', function () {
      window.HideLoading();
    })
    document.addEventListener('pjax:send', function () {
      window.ShowLoading();
    })
    document.addEventListener('pjax:error', function () {
      window.HideLoading();
    })
	</script>
</div>

  

  <script>
    var pjax = new Pjax({
      elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([no-pjax])',   // 拦截正常带链接的 a 标签
      selectors: ["#pjax-container","title"],                                   // 根据实际需要确认重载区域
      cacheBust: false,   // url 地址追加时间戳，用以避免浏览器缓存
      timeout: 5000
    });

    document.addEventListener('pjax:send', function (e) {

      try {
        var currentUrl = window.location.pathname;
        var targetUrl = e.triggerElement.href;
        var banUrl = [""];
        if (banUrl[0] != "") {
          banUrl.forEach(item => {
            if(currentUrl.indexOf(item) != -1 || targetUrl.indexOf(item) != -1) {
              window.location.href = targetUrl;
            }
          });
        }
      } catch (error) {}

      $(window).unbind('resize');
      $(window).unbind('scroll');
      $(document).unbind('scroll');
      $(document).unbind('click');
      $('body').unbind('click');

    })
    
    document.addEventListener('pjax:complete', function () {
      $('script[data-pjax], .pjax-reload script').each(function () {
        $(this).parent().append($(this).remove());
      });
    });

    document.addEventListener('pjax:error', function (e) {
      window.location.href = e.triggerElement.href;
    })
    
    // 刷新不从顶部开始
    document.addEventListener("DOMContentLoaded", function () {
      history.scrollRestoration = 'auto';
    })
  </script>



  </body>
</html>